#ifndef PERSON_H
#define PERSON_H

#include <QObject>
#include <QString>
#include <QDate>
#include <QtQml>

class Info : public QObject
{
    Q_OBJECT
    Q_PROPERTY(QString name READ getName WRITE setName NOTIFY nameChanged)
    Q_PROPERTY(quint32 age READ getAge WRITE setAge NOTIFY ageChanged)
    Q_PROPERTY(QDate date READ getDate WRITE setDate NOTIFY dateChanged)

    //此种方法会多一个元数据json文件，记录数据的数据
    //QML_ELEMENT
public:
    //使用父类的构造函数(继承父类的构造)
    using QObject::QObject;
    void setName(QString name) noexcept;
    QString getName() const noexcept;
    void setAge(quint32 age) noexcept;
    quint32 getAge() const noexcept;
    void setDate(QDate date) noexcept;
    QDate getDate() const noexcept;

signals:
    void nameChanged();
    void ageChanged();
    void dateChanged();


private:
    QString m_name;
    quint32 m_age;
    QDate m_date;
};

class Person : public QObject
{
    Q_OBJECT
public:
    using QObject::QObject;
    Person(QString name, quint32 age):m_name(name), m_age(age) {}

    Q_INVOKABLE void printInfo() const noexcept;

public slots:
    void clickDemo() const noexcept;
    void countDemo(int count) const noexcept;

signals:
    void qmlCall(QString) const;

private:
    QString m_name;
    quint32 m_age;
};


class InfoFor7 : public QObject
{
    Q_PROPERTY(QString name READ getName WRITE setName NOTIFY nameChanged)
    Q_PROPERTY(quint32 age READ getAge WRITE setAge NOTIFY ageChanged)
    Q_OBJECT
    QML_ANONYMOUS
public:
    //使用父类的构造函数(继承父类的构造)
    using QObject::QObject;
    void setName(QString name) {m_name = name;}
    QString getName() {return m_name;}
    void setAge(quint32 age) {m_age = age;}
    int getAge() {return m_age;}
signals:
    void nameChanged();
    void ageChanged();

private:
    QString m_name;
    quint32 m_age;

};
class PersonFor7 : public QObject
{
    Q_OBJECT
    QML_ATTACHED(InfoFor7)//直接将InfoFor7附加进来，qml能使用PersonFor7就能直接使用他里面的name和age属性
public:
    using QObject::QObject;

    //返回附加对象的实例，能直接使用InfoFor7的属性
    static InfoFor7* qmlAttachedProperties(QObject *obj);
};

#include <QtQuick>
class GtPerson : public QQuickItem
{
    Q_OBJECT
    Q_PROPERTY(QString name READ getName WRITE setName NOTIFY nameChanged)
    Q_PROPERTY(quint32 age READ getAge WRITE setAge NOTIFY ageChanged)
public:
    using QQuickItem::QQuickItem;

    void setName(QString name) noexcept;
    QString getName() const noexcept;
    void setAge(quint32 age) noexcept;
    quint32 getAge() const noexcept;

signals:
    void nameChanged();
    void ageChanged();
private:
    quint32 m_age;
    QString m_name;
};
class GtJob : public QQuickItem
{
    Q_OBJECT
    Q_PROPERTY(QQmlListProperty<GtPerson> students READ getStudents NOTIFY studentsChanged)
    Q_PROPERTY(GtPerson *squad READ getSquad WRITE setSquad NOTIFY squadChanged)

public:

    using StudentListType = QList<GtPerson *>;
    //Q_INVOKABLE void append(GtPerson *student) noexcept;
    QQmlListProperty<GtPerson> getStudents() noexcept;
    GtPerson* getSquad() noexcept;
    void setSquad(GtPerson *suqad) noexcept;
    static void AppendFunction(QQmlListProperty<GtPerson> *students, GtPerson *stu) noexcept;
    static int CountFunction(QQmlListProperty<GtPerson> *students) noexcept;
    static GtPerson* AtFunction(QQmlListProperty<GtPerson> *students, int index) noexcept;
    static void ClearFunction(QQmlListProperty<GtPerson> *students) noexcept;
    static void ReplaceFunction(QQmlListProperty<GtPerson> *students, int index, GtPerson *stu) noexcept;
    static void RemoveLastFunction(QQmlListProperty<GtPerson> *students) noexcept;

signals:
    void studentsChanged();
    void squadChanged();

private:
    StudentListType m_student;
    GtPerson m_squad;
};

#endif // PERSON_H
